
/***  DOCUMENTATION LAYER

	Akwa Form Jini File

	Last Update: Apr 2007
	Author: Tom at klenwell@gmail.com
	License: GPL License (http://www.opensource.org/licenses/gpl-license.php)

NOTES
	The idea is that you'd call this once and it would define this class's meta data,
	auto-load all the other files it requires, and declare the base class of your package.
	
	IMPORTANT : the auto src-detection below fails when a class.ini.js files that includes
	other files is called in the HEAD of a document.  However, it works in my tests when
	called from the BODY of a document.  Not sure why, but call original class from
	the document body to be safe. 
	
	** Be sure to rename your base class **

	To link: <script type="text/javascript" src="path/to/file.js"></script>

REFERENCE
	http://developer.mozilla.org/en/docs/JavaScript

______________________________________________________________________________*/


// package meta information
// ** EDIT THIS SECTION
/*____________________________________________________________________________*/

var META = new Object();

// Edit These Settings
META['name'] = 'AkwaForm';
META['version'] = '0.3';
META['last_update'] = 'Apr 2007';
META['license'] = 'GPL 2';
META['dirpath'] = '%TBD%';
META['filename'] = 'akwa.ini.js';	/* this should match this file's name */

// Dependant Files to Be Autoloaded 
/* relative paths will be rewritten off this file's directory, absolute paths will not be changed */
META['INCLUDE'] = [ 'akwa.core.js' ];

// Do not edit : creates/updates global NAMESPACE object to keep new class's meta settings from getting overwritten   
var NAMESPACE = ( NAMESPACE == null ) ? new Object() : NAMESPACE;
NAMESPACE[META['name']] = META;

/*____________________________________________________________________________*/


// base class constructor
// ** function identifer and this.name should match class name above
/*____________________________________________________________________________*/
function AkwaForm(_debug)	/* edit class name here */
{
	// edit class name to match META['name'] and this function's name
	this.name = 'AkwaForm';
	
	// set meta properties
	this.debug = _debug;
	this.version = NAMESPACE[this.name]['version'];
	this.filename = NAMESPACE[this.name]['filename'];
	this.dirpath = NAMESPACE[this.name]['dirpath'];
	this.INCLUDE = NAMESPACE[this.name]['INCLUDE'];
	
	// debug
	if ( this.debug ) alert(this.name + ' loaded -> dirpath : ' + this.dirpath);

	/* extend this class with an ini method and call that to pass any needed parameters */

}; // end cx
/*____________________________________________________________________________*/


// prototype extensions
// ** optional
/*____________________________________________________________________________*/

/* object debugger */
Object.prototype.debug = function(color)
{
	if ( color == null ) color = "#cc3333";
	for ( var i in this ) document.write('<div style="color:'+color+';">' + i + ' : ' + this[i] + '</div>');
};

/* error handler */
Object.prototype.trigger_error = function(message, fatal)
{
	if ( fatal == null ) fatal = 0;
	alert('EcmaForm error : ' + message);
	if ( fatal ) __fatal_error();
};

/*____________________________________________________________________________*/


// autoload dependant files
// ** DO NOT EDIT THIS SECTION
/*____________________________________________________________________________*/


// autoload function (this is what script.aculo.us currently uses)
function _autoload(url) { document.write('<script type="text/javascript" src="'+url+'"></script>'); }

// dynamically determine this file's directory path (META['dirpath'])
if ( META['INCLUDE'].length > 0 )
{
	// set fname regex and initialize other vars
	var _regex_fname = new RegExp(META['filename'], 'i');
	var _regex_http = new RegExp('^http', 'i');
	var _script_src = '%empty%';
		
	// create scriptlist object
	var ScriptList = document.getElementsByTagName('script');
	
	// cycle scriptlist looking for this files src value
	for ( var i=0; i < ScriptList.length; i++ )
	{
		var _src = ScriptList[i].getAttribute('src');
		if ( _src != null && _src.search(_regex_fname) != -1 )
		{
			var ScriptSrcNode = ScriptList[i];
			_script_src = _src;
			break;
		}
	}
	
	// did we find the src we were looking for?
	if ( _script_src == '%empty%' )
	{
		alert("unable to find script source - please check init file META['filename'] setting");
		_fx_fatal_error(); 
	}
	
	// get url dirname from source
	var _ss_lio = _script_src.lastIndexOf ( '/' ); 
	META['dirpath'] = _ss_lio >= 0 ? _script_src.substring( 0, _ss_lio + 1 ) : '';
	
	// Load files
	for ( var i=0; i < META['INCLUDE'].length; i++ )
	{
		_inc = META['INCLUDE'][i];
		_new_src = ( _inc.search(_regex_http) != -1 ) ? _inc : META['dirpath'] + _inc;
		_autoload(_new_src);	/* see fx above */
		if ( 0 ) alert(_new_src);	/* debug */
	}
}

/*____________________________________________________________________________*/

